package etf.tests;

import etf.db40.IntermediateDb4o;
import etf.hibernate.IntermediateHibernate;
import etf.jdbc.IntermediateJDBC;

public class ItermediateTest extends Test{
	private IntermediateDb4o 		db4o;
	private IntermediateJDBC 		jdbc;
	private IntermediateHibernate 	hibernate;
	private int inserts[] ={100000};

	public ItermediateTest(){
		db4o 		= new IntermediateDb4o("ItermediateTest");
		hibernate 	= new IntermediateHibernate();
		jdbc 		= new IntermediateJDBC();
	}
	
	public void testInsertQueryDelete_1_on_1(){
		printSeparator(0);
		System.out.println("    TESTIRANJE SLOZENOG OBJEKTA - 1 NA 1 VEZA");
//		clear_1_on_1();
		for (int i = 0; i < inserts.length; i++){
			
			printSeparator(50); System.out.println(inserts[i] + " SLOGOVA"); printSeparator(50);
			
//			printSeparator(50);
//			System.out.println("                 INSERT");
//			printSeparator(50);
//			System.out.println("Insert " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.insert(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.insert(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.insert(inserts[i]) + " ms");
			
//			printSeparator(50);
//			System.out.println("                 QUERY");
//			printSeparator(50);
//			System.out.println("------------Bez indeksa-------------------------");
//			System.out.println("Db40           : " + db4o.query(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.query(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.query(inserts[i]) + " ms");
			
			
//			System.out.println("------------Sa indeksom-------------------------");
//			System.out.println("Db40           : " + db4o.indexedQuery(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.indexedQuery(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.indexedQuery(inserts[i]) + " ms");
			
//			printSeparator(50);
//			System.out.println("                 UPDATE");
//			printSeparator(50);
//			System.out.println("Db40           : " + db4o.update(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.update(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.update(inserts[i]) + " ms");
			
//			printSeparator(50);
//			System.out.println("                 DELETE");
//			printSeparator(50);
//			System.out.println("Brisanja jednog sloga od " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.delete(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.delete(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.delete(inserts[i]) + " ms");
//			
			System.out.println("Brisanja jednog sloga od " + inserts[i] + " slogova sa indeksom");
			System.out.println("Db40           : " + db4o.indexedDelete(inserts[i]) + " ms");
			System.out.println("Hibernate/MySQL: " + hibernate.indexedDelete(inserts[i]) + " ms");
			System.out.println("JDBC/MySQL     : " + jdbc.indexedDelete(inserts[i]) + " ms");
			
			printSeparator(50);
//			clear_1_on_1();
		}
	}
	
	public void testInsertAndQuery_1_to_N(){
		printSeparator(0);
		System.out.println("    TESTIRANJE INSERT-A QUERY-A SLOZENOG OBJEKTA - 1 NA N VEZA");
//		clear_1_on_N();
		for (int i = 0; i < inserts.length; i++){
			
//			printSeparator(60); 
//			System.out.println(inserts[i] + " SLOGOVA"); 
//			printSeparator(60);
//			
//			printSeparator(50);
//			System.out.println("                 INSERT");
//			printSeparator(50);
//			System.out.println("Insert " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.insert_1_to_N(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.insert_1_to_N(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.insert_1_to_N(inserts[i]) + " ms");
			
			printSeparator(50);
			System.out.println("                 QUERY");
			printSeparator(50);
			System.out.println("Pretrazivanje slogova " + inserts[i] + " slogova");
			System.out.println("Db40           : " + db4o.query_1_to_N(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.query_1_to_N(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.query_1_to_N(inserts[i]) + " ms");
//			
//			
//			printSeparator(50);
//			System.out.println("                 UPDATE");
//			printSeparator(50);
//			System.out.println("Update jednog sloga od " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.update_1_to_N(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.update_1_to_N(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.update_1_to_N(inserts[i]) + " ms");
//			
//			printSeparator(50);
//			System.out.println("                 DELETE");
//			printSeparator(50);
//			System.out.println("Delete jednog sloga od " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.delete_1_to_N(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.delete_1_to_N(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.delete_1_to_N(inserts[i]) + " ms");
			
			printSeparator(50);
//			clear_1_on_N();
		}
	}
	
	public void testInsertAndQuery_N_to_N(){
		printSeparator(0);
		System.out.println("    TESTIRANJE INSERT-A I QUERY-A SLOZENOG OBJEKTA - N NA N VEZA");
//		clear_N_on_N();
		for (int i = 0; i < inserts.length; i++){
			
			printSeparator(60); 
			System.out.println(inserts[i] + " SLOGOVA"); 
			printSeparator(60);
			
//			printSeparator(50);
//			System.out.println("                 INSERT");
//			printSeparator(50);
//			System.out.println("Insert " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.insert_N_to_N(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.insert_N_to_N(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.insert_N_to_N(inserts[i]) + " ms");
			
			printSeparator(50);
			System.out.println("                 QUERY");
			printSeparator(50);
			System.out.println("Pretraga sloga od " + inserts[i] + " slogova");
			System.out.println("Db40           : " + db4o.query_N_to_N(inserts[i]) + " ms");
			System.out.println("Hibernate/MySQL: " + hibernate.query_N_to_N(inserts[i]) + " ms");
			System.out.println("JDBC/MySQL     : " + jdbc.query_N_to_N(inserts[i]) + " ms");
			printSeparator(50);
			
//			printSeparator(50);
//			System.out.println("                 UPDATE");
//			printSeparator(50);
//			System.out.println("Update jednog sloga od " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.update_N_to_N(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.update_N_to_N(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.update_N_to_N(inserts[i]) + " ms");
//			printSeparator(50);
//			
//			printSeparator(50);
//			System.out.println("                 DELETE");
//			printSeparator(50);
//			System.out.println("Update jednog sloga od " + inserts[i] + " slogova");
//			System.out.println("Db40           : " + db4o.delete_N_to_N(inserts[i]) + " ms");
//			System.out.println("Hibernate/MySQL: " + hibernate.delete_N_to_N(inserts[i]) + " ms");
//			System.out.println("JDBC/MySQL     : " + jdbc.delete_N_to_N(inserts[i]) + " ms");
//			printSeparator(50);
//			clear_N_on_N();
		}
	}
	
	private void clear_1_on_1(){
		db4o.clear_1_on_1();
		hibernate.clear_1_on_1();
		jdbc.clear_1_on_1();
	}
	
	private void clear_1_on_N(){
		db4o.clear_1_on_N();
		hibernate.clear_1_on_N();
		jdbc.clear_1_on_N();
	}
	
	private void clear_N_on_N(){
		db4o.clear_N_on_N();
//		hibernate.clear_N_on_N();
		jdbc.clear_N_on_N();
	}
	
	public void closeSessions(){
		db4o.closeDatabase();
	}
}
